#ifndef __LWIN_H__
#define __LWIN_H__

#include <QtGui>
#include <QtCore>
#ifdef Q_OS_WIN32
#include <windows.h>
#endif
class LCoinWidget;

struct history {int h_type; int h_value; }; // undo/redo history

class LWin : public QMainWindow
{
    Q_OBJECT

public:
    /*INTERFACE*/
    LWin(QWidget *parent = 0, Qt::WFlags f = 0 );

private:
    /* ENUMS */
    enum CoinType {Slag = 0, Danar, Crown, Orb};
    
    /* WIDGETS */
    LCoinWidget *orb;
    LCoinWidget *crown;
    LCoinWidget *danar;
    LCoinWidget *slag;
    QListWidget *log;
    QFrame *coin;
    QFrame *central;
    QLineEdit *edTotal;
    QToolBar *tbMain;
    QSystemTrayIcon *m_icon;
    QMenu *menu;
    
    /* ACTIONS */
    QAction *actTop;
    QAction *actMute;
    QAction *actUndo;
    QAction *actRedo;
    QAction *actClear;
    QAction *actInsert;
    QAction *actInsert2;
    QAction *actSplit;
    QAction *actCopy;
    QAction *actSelectAll;
    QAction *pasteAct;
    QAction *actClose;
    QAction *actSetVisible;
    QAction *actPaste;

    /* METHODS */
    void createActions();
    void createToolbars();
    void writeSettings();
    void readSettings();
    void popUpMessage();
    void setupMenu();
    void logText(QString str, Qt::GlobalColor color = Qt::black);
    LWin::CoinType resolveCoinType(const QString c_type); 
    void addCoin(const LWin::CoinType c_type, const int num);

    /* DATA MEMBERS */
    int m_audio;
    QList<history> m_history;
    QList<history> m_trash;
    int m_undo;
    QPoint m_pos;
    QSize m_size;
    QHash <CoinType, QString> coin_lookup;
    int m_total;
    bool m_showing;
    bool m_flash_on;
    int m_flash_cnt;
    QTimer *m_flash_timer;
    QTimer *m_update_timer;
    
protected:
    void closeEvent(QCloseEvent*);
    void changeEvent(QEvent*);
#ifdef Q_OS_WIN32
    bool winEvent(MSG *m, long *result);
#endif

private slots:
    void pasteLoot();
    void figureSplit();
    void updateTotal();
    void toggleAlwaysOnTop(bool);
    void toggleCompactMode(bool);
    void toggleAudio(bool);
    void historyBack();
    void historyForward();
    void historyClear();
    void addHistory(int h_type, int h_value);
    void copyData();
    void selectAll();
    void iconClicked(QSystemTrayIcon::ActivationReason);
    void toggleVisible();
    void flashIcon();
    void periodicUpdates();
};

#endif  // __LWIN_H__
